home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Events / Tick.h < prev   
Text File  |  2000-06-23  |  1KB  |  47 lines

  1. // Tick.h
  2.  
  3. #ifndef Tick_h
  4. #define Tick_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9.  
  10. #include <Events.h>
  11.  
  12. class Tick
  13.   {
  14.     private:
  15.         int32 time;
  16.     
  17.     public:
  18.         explicit Tick( uint32 t )            : time( int32( t ) )        {}
  19.         
  20.         int32 Time() const                    { return time; }
  21.  
  22.         static Tick Now()                        { return Tick( TickCount() ); }
  23.         
  24.         void operator+=( int32 d )            { time += d; }
  25.         void operator-=( int32 d )            { time -= d; }
  26.         
  27.         const Tick operator+( int32 d ) const    { return Tick( uint32( time + d ) ); }
  28.         const Tick operator-( int32 d ) const    { return Tick( uint32( time - d ) ); }
  29.  
  30.         int32 operator-( Tick t ) const    { return time - t.time; }
  31.         
  32.         bool operator==( Tick t ) const    { return time == t.time; }
  33.         bool operator!=( Tick t ) const    { return time != t.time; }
  34.         
  35.         // We avoid the ordinary comparisons here so that we
  36.         // can compare times (locally) around the time when
  37.         // TickCount overflows. 
  38.         bool operator<=( Tick t ) const    { return time - t.time <= 0; }
  39.         bool operator>=( Tick t ) const    { return time - t.time >= 0; }
  40.         bool operator<( Tick t ) const    { return time - t.time < 0; }
  41.         bool operator>( Tick t ) const    { return time - t.time > 0; }
  42.         
  43.         void WaitFor() const;
  44.   };
  45.  
  46. #endif
  47.